﻿using System;
using System.Windows.Forms;

namespace RegExpRegExpGenerator
{
    public partial class AddRule : Form
    {
        public AddRule()
        {
            InitializeComponent();
        }

        private void btnAddRule_Click(object sender, EventArgs e)
        {
            Add(); // Append to list in RegExpGenerator.cs
        }

        /// <summary>
        ///     Enter to submit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddRule_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Add();
            }
        }

        public void Add()
        {
            if (!string.IsNullOrWhiteSpace(txtPattern.Text) && !string.IsNullOrWhiteSpace(txtName.Text))
            {
                // Add string for listbox purposes
                RegExpGenerator.rules.Add(new LexRule(txtName.Text, txtPattern.Text, chkIgnore.Checked).ToString());

                // Add LexRule for code generation purposes
                RegExpGenerator.lexRules.Add(new LexRule(txtName.Text, txtPattern.Text, chkIgnore.Checked));

                // Close window
                Close();
            }
            else
            {
                MessageBox.Show("Insufficient properties.", "RegExpRegExpGenerator - Error");
            }
        }

        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            treeView1.Nodes.Count.ToString();
            if (treeView1.Nodes.ContainsKey("Matching Complete Lines"))
            {
                txtName.Text = "Matching Complete Lines";
                txtPattern.Text = "[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]";
                txtDescription.Text =
                    "Shows how to match complete lines in a text file rather than just the part of the line that satisfies a certain requirement. Also shows how to match lines in which a particular regex does not match.";
            }

            if (treeView1.Nodes.ContainsKey("Finding or Verifying Credit Card Numbers"))
            {
            }

            if (treeView1.Nodes.ContainsKey("Matching Valid Dates"))
            {
            }

            if (treeView1.Nodes.ContainsKey("Matching an Email Address"))
            {
            }

            if (treeView1.Nodes.ContainsKey("Floating Point Number"))
            {
            }

            if (treeView1.Nodes.ContainsKey("Numeric Ranges"))
            {
            }
        }
    }
}